package cqut.wys.controller;

import cqut.wys.hello.Greeting;
import cqut.wys.hello.HelloMessage;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;

/**
 * @author wuyoushan@zbj.com
 * @date 2017/4/5.
 */
@Controller
public class GreetingController {

    //@MessageMapping注释确保如果将消息发送到目标"/hello"，则会调用greeting（）方法。
    @MessageMapping("/hello")
    @SendTo("/topic/greetings")     //消息发送/topic/greetings
    public Greeting greeting(HelloMessage message) throws InterruptedException {
        Thread.sleep(1000);     //simulated delay
        return new Greeting("Hello, "+message.getName()+"|");
    }
}
